<?php
class Silk_Mapi_CategoryController extends Silk_Mapi_Controller_Action{
    public function IndexAction() {
        echo "OK";
    }

    /*
	* 
    */
    public function listAction()
    {
    	$rootId = Mage::getConfig()->getNode('default/mapi/general/root_category');
    	$root = Mage::getModel('catalog/category')->load($rootId);
    	$categorys = $root->getChildrenCategories();
    	$data = array();
    	foreach($categorys as $category)
    	{
    		$cate = array(
    			'id'=>$category->getId(),
    			'name'=>$category->getName(),
    			'childs'=>array());
    		// if($category->hasChildren())
    		// {
    		// 	$childCates = array();
    		// 	$childs = $category->getChildrenCategories();
    		// 	foreach($childs as $child)
    		// 	{
    		// 		$childCates[] = array('id'=>$child->getId(), 'name'=>$child->getName());
    		// 	}
    		// 	$cate['childs'] = $childCates;
    		// }
    		$data[] = $cate;
    	}
        $data[] = array(
            'id'=>'100',
            'name'=>'最近购买',
            'childs'=>array()
            );
    	$this->render($data);
    }
}